package Controlador;

import java.util.Date;
import java.util.Collection;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.Iterator;
import Modelo.*;

public class FiltroControlador {

	public void soft(String nombresalaa, int numeroestudiantess, String numeroEstudiantes, String nomsoftware, Date fechaReserva, int hora)
	{
		
		final EntityManagerFactory emf;
		final EntityManager em;
		
		
		try{
			
			 emf = Persistence.createEntityManagerFactory("ReservarSalas");
			 em = emf.createEntityManager();
	        
			 Sala inst = new Sala();
			 
			 
			 inst.setNombresala(nombresalaa);
			 inst.setNumeroestudiantes(numeroestudiantess);
			 //inst.setHora(em.find(Hora.class, hora));
			// inst.setSoftwares(em.find(Software.class, nomsoftware));
			 
			 
			 
		
			 em.getTransaction().begin();
			  em.persist(inst);
			  em.getTransaction().commit();
			  em.close();
			
			}
			catch(Exception e){
				
			 System.out.println(e);
			 e.printStackTrace();
			} 
		}
	
	public Collection desplegarSoftware (){
	    EntityManagerFactory emf = Persistence.createEntityManagerFactory("ReservarSalas");
	    EntityManager em = emf.createEntityManager();
	   
	    FiltroControlador service = new FiltroControlador();

	    em.getTransaction().begin();

	    
	    Collection emp = em.createQuery("SELECT u FROM Software u").getResultList();
	    for (Iterator i = emp.iterator(); i.hasNext();) {
	    	Software e = (Software) i.next();
	      
	      System.out.println( e.getNombresoftware() );
	    }
	    
	    
	    em.getTransaction().commit();
	    em.close();
	    emf.close();
		return emp;
			
		}
	
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		FiltroControlador pru = new FiltroControlador();
		
		pru.desplegarSoftware();
	}

}

